<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/10/21
 * Time: 16:27
 */

namespace app\adminapiv3\controller;

use  app\adminapiv3\service;
use think\Request;

//登录
class LoginController extends BaseController
{
    /**
     * @name 登录
     * @author wx
     * @date 2019/10/21 16:28
     */
    public function login(Request $request)
    {
        //接收参数
        $params = $request->only([
            'name','password','captcha'
        ],'post');

        //数据验证
        $this->validate($params,'ServerUser.login');

        //图形验证码不区分大小写
        $params['captcha'] = strtolower($params['captcha']);
        $loginServer = new service\LoginService();
        $return_data = $loginServer->login($params['name'], $params['password'],$params['captcha']);
        return $this->jsonOutPut($return_data);
    }

    /**
     * @name 验证码
     * @author wx
     * @date 2019/10/21 16:29
     */
    public function code()
    {
        $codeServer = new service\ServerRandCodeService();
        $code = $codeServer->createCaptcha();
        $data['captcha_code'] = $code;
        return $this->jsonOutPut($data);
    }

}